using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using SJVars;
using System;

namespace yWriter6
{
	[StandardModule]
	internal sealed class modWordcount
	{
		public static void BreakAndHash(ref Collection colHash, string StringtoHash)
		{
			//Discarded unreachable code: IL_02e7, IL_02fe, IL_0309, IL_0319, IL_03db, IL_03dd, IL_03f1, IL_0413
			int num = default(int);
			int num5 = default(int);
			try
			{
				ProjectData.ClearProjectError();
				num = 2;
				int num2 = 2;
				if (Strings.Len(StringtoHash) != 0)
				{
					num2 = 4;
					StringtoHash = Strings.Replace(StringtoHash, "\r\n", " ");
					num2 = 5;
					StringtoHash = Strings.Replace(StringtoHash, "\r", " ");
					num2 = 6;
					StringtoHash = Strings.Replace(StringtoHash, "\n", " ");
					num2 = 7;
					StringtoHash = Strings.Replace(StringtoHash, "\t", " ");
					num2 = 8;
					StringtoHash = Strings.Replace(StringtoHash, "=", " ");
					num2 = 9;
					StringtoHash = Strings.Replace(StringtoHash, ",", " ");
					num2 = 10;
					StringtoHash = Strings.Replace(StringtoHash, "*", " ");
					num2 = 11;
					StringtoHash = Strings.Replace(StringtoHash, "-", " ");
					num2 = 12;
					StringtoHash = Strings.Replace(StringtoHash, Conversions.ToString(Strings.Chr(146)), "'");
					num2 = 13;
					StringtoHash = Strings.Replace(StringtoHash, Conversions.ToString(Strings.Chr(145)), "'");
					num2 = 14;
					StringtoHash = Strings.Replace(StringtoHash, "'s", "");
					num2 = 15;
					StringtoHash = Strings.Replace(StringtoHash, "'ve", Conversions.ToString(Strings.Chr(146)) + "ve");
					num2 = 16;
					StringtoHash = Strings.Replace(StringtoHash, "'t", Conversions.ToString(Strings.Chr(146)) + "t");
					num2 = 17;
					StringtoHash = Strings.Replace(StringtoHash, "'ll", Conversions.ToString(Strings.Chr(146)) + "ll");
					num2 = 18;
					StringtoHash = Strings.Replace(StringtoHash, "'", "");
					num2 = 19;
					StringtoHash = clsShared.cText.RemoveDblSpaces(StringtoHash);
					num2 = 20;
					int num3 = 1;
					HashRec hashRec = default(HashRec);
					do
					{
						num2 = 22;
						int num4 = num3;
						num2 = 23;
						num3 = Strings.InStr(num4 + 1, StringtoHash, " ");
						num2 = 24;
						string word;
						if (num3 > 0)
						{
							num2 = 25;
							word = Strings.Trim(Strings.Mid(StringtoHash, num4, num3 - num4 + 1));
						}
						else
						{
							num2 = 27;
							if (num3 == 0)
							{
								num2 = 28;
								word = Strings.Trim(Strings.Mid(StringtoHash, num4));
							}
							else
							{
								num2 = 30;
								word = "";
							}
						}
						num2 = 31;
						word = CleanThisWord(word).Trim();
						num2 = 32;
						if (Operators.CompareString(word, "", TextCompare: false) != 0)
						{
							num2 = 33;
							if (colHash.Contains(word))
							{
								num2 = 34;
								object obj = colHash[word];
								hashRec = ((obj != null) ? ((HashRec)obj) : default(HashRec));
								num2 = 35;
								hashRec.Count++;
								num2 = 36;
								colHash.Remove(word);
							}
							else
							{
								num2 = 38;
								hashRec.Word = word;
								num2 = 39;
								hashRec.Count = 1;
							}
							num2 = 40;
							colHash.Add(hashRec, word);
						}
						num2 = 41;
					}
					while (num3 != 0);
				}
			}
			catch (Exception obj2) when (( num != 0) & (num5 == 0))
			{
				ProjectData.SetProjectError(obj2);
				/*Error near IL_0411: Could not find block for branch target IL_03dd*/;
			}
			if (num5 != 0)
			{
				ProjectData.ClearProjectError();
			}
		}

		private static string CleanThisWord(string Word)
		{
			Word = Word.Replace("<", "");
			Word = Word.Replace(">", "");
			Word = Word.Replace("`", "");
			Word = Word.Replace("~", "");
			Word = Word.Replace("^", "");
			Word = Word.Replace("\"", "");
			Word = Word.Replace("(", "");
			Word = Word.Replace(")", "");
			Word = Word.Replace("{", "");
			Word = Word.Replace("}", "");
			Word = Word.Replace("[", "");
			Word = Word.Replace("]", "");
			Word = Word.Replace("!", "");
			Word = Word.Replace("?", "");
			Word = Word.Replace(".", "");
			Word = Word.Replace("_", "");
			return Strings.Trim(Word);
		}
	}
}
